//
//  MyHouseViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/8/23.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "MyHouseViewController.h"

#import "MyHouseCell.h"
#import "FirstView.h"
#import "SecondView.h"
#import "ThreeView.h"
#import "FourView.h"
#import "UpdateHouseViewController.h"

@interface MyHouseViewController ()<UITableViewDelegate,UITableViewDataSource>{
    UILabel *labLine;
    UIView *view1;
    UIScrollView *sclView;
    UIButton *btnR;
    UIButton *btnL;
}

@property (nonatomic,strong)UITableView *tableView;

@end

@implementation MyHouseViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    self.view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
    
    [self loadNav];
    [self loadUI1];
    [self loadUI2];
    
}

- (void)loadNav{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 64)];
    view.backgroundColor = [UIColor whiteColor];
    view.userInteractionEnabled = YES;
    [self.view addSubview:view];
    
    btnL = [UIButton buttonWithType:UIButtonTypeCustom];
    btnL.frame = CGRectMake(ScreenWidth/2-75, 30, 65, 25);
    btnL.titleLabel.font = [UIFont systemFontOfSize:15.0];
    //btnL.backgroundColor = [UIColor grayColor];
    [btnL setTitle:@"我的房源" forState:UIControlStateNormal];
    [btnL setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btnL addTarget:self action:@selector(clickL) forControlEvents:UIControlEventTouchUpInside];
    btnL.titleLabel.font = [UIFont systemFontOfSize:15.0];
    [view addSubview:btnL];
    
    btnR = [UIButton buttonWithType:UIButtonTypeCustom];
    btnR.frame = CGRectMake(ScreenWidth/2+10, 30, 65, 25);
    btnR.titleLabel.font = [UIFont systemFontOfSize:15.0];
    //btnR.backgroundColor = [UIColor grayColor];
    [btnR setTitle:@"我的发布" forState:UIControlStateNormal];
    [btnR setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btnR addTarget:self action:@selector(clickR) forControlEvents:UIControlEventTouchUpInside];
    btnR.titleLabel.font = [UIFont systemFontOfSize:15.0];
    [view addSubview:btnR];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"箭头"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    [btn makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(btnL.centerY);
        make.left.equalTo(0);
        make.width.equalTo(40);
        make.height.equalTo(40);
    }];
    
    labLine = [[UILabel alloc] initWithFrame:CGRectMake(btnL.frame.origin.x+18, 60, 30, 4)];
    labLine.backgroundColor = [UIColor redColor];
    labLine.layer.cornerRadius = 5.0;
    [view addSubview:labLine];
    
}

- (void)clickBack{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)clickL{
    [UIView animateWithDuration:0.3 animations:^{
        labLine.frame = CGRectMake(btnL.frame.origin.x+18, 60, 30, 4);
    }];
    _tableView.hidden = NO;
    sclView.hidden = YES;
}

- (void)clickR{
    [UIView animateWithDuration:0.3 animations:^{
        labLine.frame = CGRectMake(btnR.frame.origin.x+18, 60, 30, 4);
    }];
    _tableView.hidden = YES;
    sclView.hidden = NO;
}

- (void)loadUI1{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64+10, ScreenWidth, 149) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.scrollEnabled = NO;
    [self.view addSubview:_tableView];
    
}

- (void)loadUI2{
    sclView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64)];
    sclView.backgroundColor = COLOR_RGB(242, 242, 242, 1);
    sclView.contentSize = CGSizeMake(ScreenWidth, 1417);
    sclView.hidden = YES;
    [self.view addSubview:sclView];
    
    UIView *v1 = [[[NSBundle mainBundle] loadNibNamed:@"FirstView" owner:nil options:nil] lastObject];
    v1.frame = CGRectMake(0, 0, ScreenWidth, 200);
    [sclView addSubview:v1];
    
    UIView *v2 = [[[NSBundle mainBundle] loadNibNamed:@"SecondView" owner:nil options:nil] lastObject];
    v2.frame = CGRectMake(0, v1.frame.size.height+v1.frame.origin.y+10, ScreenWidth, 300);
    [sclView addSubview:v2];
    
    UIView *v3 = [[[NSBundle mainBundle] loadNibNamed:@"ThreeView" owner:nil options:nil] lastObject];
    v3.frame = CGRectMake(0, v2.frame.size.height+v2.frame.origin.y+10, ScreenWidth, 293);
    [sclView addSubview:v3];
    //500+293+534+50+40
    UIView *v4 = [[[NSBundle mainBundle] loadNibNamed:@"FourView" owner:nil options:nil] lastObject];
    v4.frame = CGRectMake(0, v3.frame.size.height+v3.frame.origin.y+10, ScreenWidth, 534);
    [sclView addSubview:v4];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = [UIColor redColor];
    btn.frame = CGRectMake(0, v4.frame.size.height+v4.frame.origin.y+10, ScreenWidth, 50.0);
    [btn setTitle:@"确定发布" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [sclView addSubview:btn];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId = @"Cell";
    MyHouseCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MyHouseCell" owner:nil options:nil] lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.btnDel.layer.cornerRadius = 5.0;
    cell.btnDel.layer.borderWidth = 1.0;
    cell.btnDel.layer.borderColor = [UIColor redColor].CGColor;
    
    cell.btnUpdate.layer.cornerRadius = 5.0;
    cell.btnUpdate.layer.borderWidth = 1.0;
    cell.btnUpdate.layer.borderColor = [UIColor redColor].CGColor;
    
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UpdateHouseViewController *house = [[UpdateHouseViewController alloc] init];
    [self.navigationController pushViewController:house animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 140.0;
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
